/*
 * Rectangle.cpp
 *
 *  Created on: 2010-9-12
 *      Author: try
 */

#include "Rectangle.h"
#include "ControlPoint.h"
#include "../WorkLayer.h"

namespace S {

  Rectangle::Rectangle(real x, real y, real w, real h)
  :Shape(x, y, w, h) {

//    //初台化路径
//    createPath();
  }

  Rectangle::~Rectangle() {
    if (path)
      delete path;
  }

  void Rectangle::createPath() {
    if (path) delete path;
    path = new Gdiplus::GraphicsPath();
    createBoundRect();

    getBoundRect(&shapeRect, -1.0f);
    if(!(shapeRect.Width < 0 || shapeRect.Height < 0)){
      path->AddRectangle(shapeRect);
    }

    //构建控制点数据
    if(isSelected()){
      buildControlPoint();
    }

    setModified(true);
  }

  void Rectangle::draw(Gdiplus::Graphics* g) {
    //绘制椭圆
    g->FillPath(brush, path);
    g->DrawPath(pen, path);

    setModified(false);
    setRedraw(false);
  }

}
